---
title: "Spring Boot Embedded Tomcat Server"
date: 2020-9-29
categories:
- java
- spring
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org00c92d6">添加Value</a></li>
</ul>
</div>
</div>
<p>
通过 TomcatContextCustomizer 这个类对内置的服务器进行配置：定义子类，声明成Bean
</p>
<div class="outline-2" id="outline-container-org00c92d6">
<h2 id="org00c92d6">添加Value</h2>
<div class="outline-text-2" id="text-org00c92d6">
<p>
示例
</p>
<div class="org-src-container">
<pre class="src src-java">
<span style="font-weight: bold; text-decoration: underline;">@Bean</span>
<span style="font-weight: bold;">public</span> <span style="font-weight: bold; text-decoration: underline;">TomcatContextCustomizer</span> <span style="font-weight: bold;">stuckCustomizer</span>() {
    <span style="font-weight: bold;">return</span> <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">TomcatContextCustomizer</span>() {
        <span style="font-weight: bold; text-decoration: underline;">@Override</span>
        <span style="font-weight: bold;">public</span> <span style="font-weight: bold; text-decoration: underline;">void</span> <span style="font-weight: bold;">customize</span>(<span style="font-weight: bold; text-decoration: underline;">Context</span> <span style="font-weight: bold; font-style: italic;">context</span>) {
            <span style="font-weight: bold; text-decoration: underline;">StuckThreadDetectionValve</span> <span style="font-weight: bold; font-style: italic;">value</span> = <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">StuckThreadDetectionValve</span>();
            <span style="font-weight: bold; font-style: italic;">// </span><span style="font-weight: bold; font-style: italic;">value.setInterruptThreadThreshold();</span>
            value.setThreshold(10);
            context.getParent().getPipeline().addValve(value);
        }
    };
}

</pre>
</div>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2020-9-29</p>
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
